package com.totowoo.shirodemo.security;

import java.util.LinkedHashMap;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.totowoo.shirodemo.dao.PermissionDao;
import com.totowoo.shirodemo.model.Permission;

public class FilterChainDefinitionMapFactory {
	private static final Logger log = LoggerFactory.getLogger(FilterChainDefinitionMapFactory.class);
	
	@Autowired
	private PermissionDao permissionDao;
	
	private LinkedHashMap<String, String> filterChainDefinitionMap = new LinkedHashMap<>();

	public LinkedHashMap<String, String> getFilterChainDefinitionMap() {
				
		List<Permission> permissions = permissionDao.getPermissionList();
		for(Permission permission : permissions) {
			if(permission.getCode().contains("p:")) {
				filterChainDefinitionMap.put(permission.getUrl(), "perms[" + permission.getCode().replaceAll("p:", "") + "]");
			} else {
				filterChainDefinitionMap.put(permission.getUrl(), permission.getCode());
			}
		}
		
		return filterChainDefinitionMap;
	}

}
